﻿<%@ Page Language="c#" Codebehind="PageBrowser.aspx.cs" AutoEventWireup="False" Inherits="FilteredPageReference.Pages.PageBrowserFilteredPageReference" %>
<%@ Import Namespace="FilteredPageReference" %>
<%@ Register TagPrefix="EPiServerUI" Assembly="EPiServer" Namespace="EPiServer.Web.WebControls" %>
<%@ Register TagPrefix="EPiServerUI" Assembly="EPiServer.UI" Namespace="EPiServer.UI.WebControls" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderContentRegion" runat="server">
    <base target="_self" />
    <script type="text/javascript" src='<%= EPiServer.Shell.Paths.ToShellResource("ClientResources/EPiJQuery.js") %>'></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FullRegion" runat="server">
    <EPiServerUI:BodySettings CssClass="epi-applicationSidebar" runat="server" />

    <script type='text/javascript'>
    	//<![CDATA[
        var pageTreeView = null;
        var returnValue = false;

        function onOK() {
            if (document.getElementById('<%=selectedPageLink.ClientID %>').value == '') {
                onNothing();
                return;
            }
            SetValues(document.getElementById('<%=selectedPageLink.ClientID %>').value, document.getElementById('<%=selectedPageName.ClientID %>').value + ' [' + document.getElementById('<%=selectedPageLink.ClientID %>').value + ']');
            EPi.GetDialog().Close(returnValue);
        }

        function onNothing() {
            SetValues('', '');
            EPi.GetDialog().Close(returnValue);
        }

        function onSelf() {
            SetValues('-', '<%= TranslateForScript("/system/pagebrowser/infoselflink") %>');
            EPi.GetDialog().Close(returnValue);
        }

        function onCancel() {
            EPi.GetDialog().Close(returnValue);
        }

        function onLoad() {
            window.focus();
            if (this.activeItem) {
                this.activeItem.scrollIntoView(false);
            }
        }

        function SetValues(value, info) {
            var doc = EPi.GetDialog().dialogArguments;
            doc.getElementById('<%=ValueVariable%>').value = value;
            doc.getElementById('<%=InfoVariable%>').value = info;
            var frame = null;

            for (i = 0; i < window.opener.frames.length; i++)
            {
                if (window.opener.frames[i].name == "EditPanel")
                {
                    frame = window.opener.frames[i];
                    break;
                }
            }

            if (frame != null && frame.<%=CallBackFunctionName%> != null)
                frame.<%=CallBackFunctionName%>();
            
            returnValue = true;
        }

        function SetLocalValues(value, info) {
            document.getElementById('<%=selectedPageLink.ClientID %>').value = value;
            document.getElementById('<%=selectedPageName.ClientID %>').value = info;
        }

        function setEnabledStateOfSelfButton() {
            var doc = EPi.GetDialog().dialogArguments;

            if (doc && doc.getElementById('disablePageBrowserSelfLinkButton') && doc.getElementById('disablePageBrowserSelfLinkButton').value == 'true')
                document.getElementById('<%=selfButton.ClientID %>').disabled = true;
        }

        function initPageTreeView(treeView) {
            pageTreeView = treeView;
            pageTreeView.OnNodeSelected = OnTreeNavigation;
        }

        function OnTreeNavigation(itemDataPath) {
            var pageName = pageTreeView.GetPropertyValue(itemDataPath, "PageName");
            SetLocalValues(itemDataPath, pageName);
        }
	
		//]]>
    </script>

    <input type="hidden" id="selectedPageLink" name="selectedPageLink" runat="server" />
    <input type="hidden" id="selectedPageName" name="selectedPageName" runat="server" />
    
    <asp:PlaceHolder ID="InvalidPagePlaceHolder" runat="server" EnableViewState="false">
        <br />
        <p style="margin-left:10px"><%=LanguageHelper.Translate("/filteredPageReference/pageMustBeSaved") %></p>
        <div style="display:none">
    </asp:PlaceHolder>

    <asp:PlaceHolder ID="SessionExpiredPlaceHolder" runat="server" EnableViewState="false">
        <br />
        <p style="margin-left:10px"><%=LanguageHelper.Translate("/filteredPageReference/sessionExpired") %></p>
        <div style="display:none">
    </asp:PlaceHolder>


    <asp:PlaceHolder ID="MainFormPlaceHolder" runat="server" EnableViewState="false">
    <div class="epiemptybackground">
        <EPiServerUI:TabStrip ID="browserActionTab" runat="server" TargetID="browserTabView" OnTabClicked="actionTab_TabClicked">
	        <EPiServerUI:Tab Text="/edit/editcommand/viewmode"	Runat="server" id="Structure" />
	        <EPiServerUI:Tab Text="/edit/editcommand/favoritesmode" Runat="server"	id="Favorites" Visible="false" />
        </EPiServerUI:TabStrip>
    </div>
    
    <asp:Panel ID="browserTabView" runat="server" CssClass="episerver-pagebrowser">
    
        <asp:Panel ID="TreeViewPanel" runat="server">
            <asp:Panel ID="Panel1" runat="server" CssClass="episerver-pagebrowserSearch" Visible="true">
                <asp:Label ID="Label1" runat="server" Text="<%$ Resources: EPiServer, button.search  %>" />
                <asp:TextBox ID="searchKey" runat="server" />
                <asp:RequiredFieldValidator runat="server" ControlToValidate="searchKey" ErrorMessage="" Text="*" Display="Dynamic" ValidationGroup="Search" />
                <EPiServerUI:ToolButton ID="searchButton" OnClick="searchButton_Click" runat="server" ToolTip="<%$ Resources: EPiServer, button.search %>" SkinID="Search" ValidationGroup="Search" />
            </asp:Panel>
            <br />
            
            <asp:Panel ID="Panel2" runat="server" CssClass="episcroll episerver-pagebrowserContainer">
                
            </asp:Panel>
        </asp:Panel>
        
        <asp:Panel ID="FavoriteViewPanel" runat="server" Visible="false">
            <asp:Panel ID="Panel3" runat="server" CssClass="episcroll episerver-pagebrowserContainer2">
                
            </asp:Panel>
        </asp:Panel>
    </asp:Panel>
    
    <asp:Panel ID="Panel4" runat="server" CssClass="episerver-pagebrowserButtonContainer">
        <EPiServerUI:ToolButton ID="okButton" GeneratesPostBack="False" runat="server" OnClientClick="onOK();" Text="<%$ Resources: EPiServer, button.select %>" ToolTip="<%$ Resources: EPiServer, button.select %>" SkinID="Check" />
        <EPiServerUI:ToolButton ID="nothingButton" GeneratesPostBack="False" runat="server" OnClientClick="onNothing();" Text="<%$ Resources: EPiServer, system.pagebrowser.buttonnolink %>" ToolTip="<%$ Resources: EPiServer, system.pagebrowser.buttonnolink %>" SkinID="Delete" />
        <EPiServerUI:ToolButton Visible="false" ID="selfButton" GeneratesPostBack="False" runat="server" OnClientClick="onSelf();" Text="<%$ Resources: EPiServer, system.pagebrowser.buttonselflink %>" ToolTip="<%$ Resources: EPiServer, system.pagebrowser.buttonselflink %>" SkinID="File" />
        <EPiServerUI:ToolButton ID="cancelButton" GeneratesPostBack="False" runat="server" OnClientClick="onCancel();" Text="<%$ Resources: EPiServer, button.cancel %>" ToolTip="<%$ Resources: EPiServer, button.cancel %>" SkinID="Cancel" />
    </asp:Panel>
    </asp:PlaceHolder>
    <asp:PlaceHolder ID="InvalidPagePlaceHolder2" runat="server" EnableViewState="false">
        </div>
    </asp:PlaceHolder>

    <asp:PlaceHolder ID="SessionExpiredPlaceHolder2" runat="server" EnableViewState="false">
        </div>
    </asp:PlaceHolder>
    <EPiServerScript:ScriptEvent ID="ScriptEvent1" EventTargetClientNode="window" EventType="load" EventHandler="setEnabledStateOfSelfButton" runat="server"/>
</asp:Content>
